package com.suixinsanren.design.state.demo.demo05;

public class SoldOutState implements State {

    private final GumballMachine gumballMachine;

    public SoldOutState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("糖果已售罄，请不要投币");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("糖果已售罄，无可退还硬币");
    }

    @Override
    public void turnCrank() {
        System.out.println("糖果已售罄，无法开始游戏");
    }

    @Override
    public void dispense() {
        System.out.println("糖果已售罄，无法开始游戏");
    }

    @Override
    public void refill(int numberGumball) {
        gumballMachine.setCount(numberGumball);
        if (gumballMachine.getCount() > 0) {
            System.out.println("已补充" + numberGumball + "个硬币");
            gumballMachine.setCurrentState(gumballMachine.getNoQuarterState());
        } else {
            gumballMachine.setCurrentState(gumballMachine.getSoldOutState());
        }
    }

    @Override
    public String toString() {
        return "糖果已售罄";
    }
}
